home *** CD-ROM | disk | FTP | other *** search
- /*
- File: DarnExceptions.h
-
- Contains: QuickDraw GX to PostScript conversion code.
-
- Version: Technology: Quickdraw GX 1.1.x
-
- Copyright: © 1996-1997 by Apple Computer, Inc., all rights reserved.
- */
-
- #ifndef __EXCEPTIONS__
- #define __EXCEPTIONS__
-
- #ifndef __TYPES__
- #include <Types.h>
- #endif
-
- #ifdef __cplusplus
- extern "C" {
- #endif
-
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=mac68k
- #endif
-
- #if PRAGMA_IMPORT_SUPPORTED
- #pragma import on
- #endif
-
- #define DEBUGOFF 0
- #define DEBUGWARN 1
- #define DEBUGMIN 2
- #define DEBUGON 3
- #define DEBUGFULL 4
- #define DEBUGCRITICAL 4
- #define DEBUGFEEDBACK 5
- #define DEBUGSYM 6
- #ifndef DEBUGLEVEL
- #define DEBUGLEVEL DEBUGOFF
- #endif
-
- #ifdef debugfeedback
- #undef DEBUGLEVEL
- #define DEBUGLEVEL DEBUGFEEDBACK
- #endif
-
- #ifndef resumeLabel
- #define resumeLabel(exception) resume_##exception:
- #endif
- #define trace (StringPtr)"\p;dprintf;doTrace"
- #define notrace (StringPtr)"\p;dprintf"
- #define traceon ((DEBUGLEVEL > DEBUGWARN) && defined(TRACEON))
- #define debugon (DEBUGLEVEL > DEBUGWARN)
- #define __DEBUGSMALL ((DEBUGLEVEL == DEBUGMIN) || \
- (DEBUGLEVEL == DEBUGSYM))
- #if DEBUGLEVEL == DEBUGMIN
- #define __DebuggerBreak Debugger()
- #elif DEBUGLEVEL == DEBUGSYM
- #define __DebuggerBreak SysBreak()
- #endif
- #define QuoteExceptionString(x) #x
- /*********************************************************************
-
- ROUTINE
- void dprintf(traceOption, format, ...)
-
- DESCRIPTION
- dprintf is used like printf only the information is displayed in
- MacsBug. traceOption is used to specify whether the execution
- should continue after the break or not. format contains
- two types of objects: ordinary characters, which are displayed in
- Macsbug, and coversion specifications, each of which causes
- conversion and printing of the next successive argument to dprintf.
- Each conversion specification begins with a % and ends with a
- conversion character. Between % and the conversion character there
- may be, in order:
-
- • Zero or more flag characters, which modify the meaning of the
- conversion specification.
- • A number that specifies the minimum field width. The converted
- argument will be printed in a field at least this wide. If
- necessary it will be padded on the left (or right, if left
- adjustment is called for) to make up the field width.
- • A period, which separates the field width from the precision.
- • A number, the precision, that specifies the maximum number of
- characters to be printed from a string, or the number of digits
- after the decimal point of a floatingpoint value, or the minimum
- number of digits for an integer.
- • An h if the integer is to be printed as a short, or l if as
- long (ignored since int is long), or L to specify that the
- following e, E, f, g, or G conversion is a long double.
-
- Note: A field width or precision may be indicated by an * instead
- of a digit string. In this case, an integer arg parameter supplies
- the field width or precision. The arg parameter that is actually
- converted is not fetched until the conversion letter is seen;
- therefore, the arg paramters specifying field width or precision
- must appear immediately before the arg parameter (if any) to be
- converted.
-
- The flag characters are:
-
- - The result of the conversion will be left justified
- within the field.
- + The result of a signed conversion always begins with a
- sign (+ or -).
- space If the first character of a signed conversion is not a
- sign, a space will be prefixed to the result. This implies
- that if the space and + flags both appear, the space flag
- will be ignored.
- # The value is to be converted to an alternate form. For c,
- d, s, and u conversions, the flag has no effect. For o
- conversions, it increases the precision to force the first
- digit of the result to be zero. For x, and X conversions,
- a nonzero result will have 0x or 0X prefixed to it. For
- e, E, f, g, and G conversions, the result will always
- contain a decimal point, even if no digits follow the
- point. For g and G conversion, trailing zeros in the
- fractional part will not be removed from the result.
- 0 The 0 flag pads the field with zeros on the left only;
- this applies to d, i, o, u, x, X, e, E, f, g, and G
- conversions. The leading zeros pad the field width, and
- no space padding is performed. If both the 0 and - flags
- appear, the 0 flag is ignored. If a precision is specified
- for d, i, o, u, x, and X conversions, the 0 flag is
- ignored.
-
- The standard conversions are:
-
- d,i int Decimal number.
- o int Unsigned octal number (w/o a leading zero).
- x,X int Unsigned hexadecimal number (w/o a leading 0x
- or oX), using abcdef or ABCDEF for 10,…,15.
- u int Unsigned decimal number.
- c int Single character.
- s char* C string.
- f double [-]m.dddddd, where the number of d's is given
- by the precision (default 6).
- e,E double [-]m.dddddde±xx or [-]m.ddddddE±xx, where the
- number of d's is given by the precision
- (default 6).
- g,G double Use %e or %E if the exponent is less than -4
- or greater than or equal to the precision;
- otherwise use %f. Trailing zeros and a
- trailing decimal point are not printed.
- p void* Pointer.
- % No argument is converted; print a %.
-
- The supported MPW extensions are:
-
- P StringPtr Pascal string.
-
- Of the MPW printf convertion characters only "n" is not supported.
- In addition to the standard characters, the following are defined:
-
- b Boolean Outputs either true or false.
- j Point Used like the d option.
- J point* Fixed point. Used like the f option.
- F Fixed Used like the f option.
- T Fract Used like the f option.
- r Rect* Displays the rect with each piece seperated by
- ", ". Used like the d option.
- R rectangle* Similar to r but for fixed point rectangles.
- Used like the f option.
- M mapping. Displays the mapping seperated by ", " and
- "\n". The third column is displayed as fract.
- Used like the f option.
-
-
- dprintf requires that the MacsBug dcmd dprintf is present.
-
- Characters used: bcdefghij l nop rs u x
- EFG J LM P R T X
- Not used: a k m q t vw yz
- ABCD HI K NO Q S UVW YZ
-
- See the MPW C Reference for more information on printf.
-
- Echo " ∂n∂
- PRINT OFF,NOHDR ∂n∂
- INCLUDE 'Traps.a' ∂n∂
- PRINT ON ∂n∂
- PROC ∂n∂
- MOVEA.L SP,A0 ; Save the stackPtr ∂n∂
- _DebugStr ∂n∂
- SUBQ #4,SP ; Fix the stack ∂n∂
- ENDPROC ∂n∂
- END ∂n∂
- " | Asm -l
-
- *********************************************************************/
-
- #ifdef INSIDEOFGX
- #if BUILDING_FOR_NUKERNEL && GENERATING68K
-
- extern pascal void NewDebugStr(ConstStr255Param damnMsg)
- = {0x203C, 0xABFF, 0xABFF, 0x2078, 0x0948, 0x2050, 0x4E90};
-
- #undef DebugStr
- #define DebugStr NewDebugStr
-
- extern void dprintf(StringPtr, char [], ...)
- = {0x203C, 0xFEED, 0xABFF, 0x2278, 0x0948, 0x2251, 0x4E91};
-
- #else
-
- extern void dprintf(StringPtr, char [], ...)
- THREEWORDINLINE(0x204F, 0xABFF, 0x594F);
-
- #endif
- #else
-
- void dprintf(StringPtr debuggerCommand, char formatString[], ...);
-
- #endif
-
- /*********************************************************************
-
- ROUTINE
- void* check_dprintf(assertion, traceOption, format, ...)
-
- DESCRIPTION
- If assertion is non-zero then assertion is returned. Otherwise the
- dprintf is invoked and zero is returned.
-
- Echo " ∂n∂
- PRINT OFF,NOHDR ∂n∂
- INCLUDE 'Traps.a' ∂n∂
- PRINT ON ∂n∂
- PROC ∂n∂
- MOVE.L (SP)+,D0 ; Pop value into D0 ∂n∂
- BNE.S @1 ; If !0 then branch ∂n∂
- MOVEA.L SP,A0 ; Save the stackPtr ∂n∂
- _DebugStr ∂n∂
- SUBQ #4,SP ; Fix the stack ∂n∂
- CLR.L D0 ; Result is zero ∂n∂
- @1 SUBQ #4,SP ; Fix stack for pop ∂n∂
- ENDPROC ∂n∂
- END ∂n∂
- " | Asm -l
-
- *********************************************************************/
- #ifdef applec
- extern void *check_dprintf(void *, StringPtr, char [], ...)
- SEVENWORDINLINE(0x201F, 0x6608, 0x204F, 0xABFF, 0x594F, 0x7000, 0x594F);
- #endif
- #ifdef applec
- extern void *checkpos_dprintf(void *, StringPtr, char [], ...)
- SEVENWORDINLINE(0x201F, 0x6C08, 0x204F, 0xABFF, 0x594F, 0x7000, 0x594F);
- #endif
- #if __DEBUGSMALL
- #define check(assertion) \
- do { \
- if (assertion) ; \
- else __DebuggerBreak; \
- } while (false)
- #elif DEBUGLEVEL == DEBUGON
- #define check(assertion) \
- do { \
- if (assertion) ; \
- else { \
- dprintf(notrace, "# Assertion \"%s\" Failed\n", QuoteExceptionString(assertion)); \
- } \
- } while (false)
- #elif DEBUGLEVEL == DEBUGFULL
- #define check(assertion) \
- do { \
- if (assertion) ; \
- else { \
- dprintf(notrace, "# Assertion \"%s\" Failed\n" \
- "file %s; line %d\n", \
- QuoteExceptionString(assertion), __FILE__, __LINE__); \
- } \
- } while (false)
- #else
- #define check(assertion)
- #endif
- #if __DEBUGSMALL
- #define ncheck(assertion) \
- do { \
- if (assertion) __DebuggerBreak; \
- } while (false)
- #elif DEBUGLEVEL == DEBUGON
- #define ncheck(assertion) \
- do { \
- void* __privateAssertion = (void*)(assertion); \
- \
- if (__privateAssertion) { \
- dprintf(notrace, "# Assertion \"!(%s [= %d])\" Failed\n", \
- QuoteExceptionString(assertion), __privateAssertion); \
- } \
- } while (false)
- #elif DEBUGLEVEL == DEBUGFULL
- #define ncheck(assertion) \
- do { \
- void* __privateAssertion = (void*)(assertion); \
- \
- if (__privateAssertion) { \
- dprintf(notrace, "# Assertion \"!(%s [= %d])\" Failed\n" \
- "file %s; line %d\n", \
- QuoteExceptionString(assertion), __privateAssertion, __FILE__, __LINE__); \
- } \
- } while (false)
- #else
- #define ncheck(assertion)
- #endif
- #if __DEBUGSMALL
- #define check_action(assertion, action) \
- do { \
- if (assertion) ; \
- else { \
- __DebuggerBreak; \
- { action } \
- } while (false)
- #elif DEBUGLEVEL == DEBUGON
- #define check_action(assertion, action) \
- do { \
- if (assertion) ; \
- else { \
- dprintf(notrace, "# Assertion \"%s\" Failed\n", QuoteExceptionString(assertion)); \
- { action } \
- } \
- } while (false)
- #elif DEBUGLEVEL == DEBUGFULL
- #define check_action(assertion, action) \
- do { \
- if (assertion) ; \
- else { \
- dprintf(notrace, "# Assertion \"%s\" Failed\n" \
- "file %s; line %d\n", \
- QuoteExceptionString(assertion), __FILE__, __LINE__); \
- { action } \
- } \
- } while (false)
- #else
- #define check_action(assertion, action)
- #endif
- #if __DEBUGSMALL
- #define ncheck_action(assertion, action) \
- do { \
- if (assertion) { \
- __DebuggerBreak; \
- { action } \
- } \
- } while (false)
- #elif DEBUGLEVEL == DEBUGON
- #define ncheck_action(assertion, action) \
- do { \
- void* __privateAssertion = (void*)(assertion); \
- \
- if (__privateAssertion) { \
- dprintf(notrace, "# Assertion \"!(%s [= %d])\" Failed\n", \
- QuoteExceptionString(assertion), __privateAssertion); \
- { action } \
- } \
- } while (false)
- #elif DEBUGLEVEL == DEBUGFULL
- #define ncheck_action(assertion, action) \
- do { \
- void* __privateAssertion = (void*)(assertion); \
- \
- if (__privateAssertion) { \
- dprintf(notrace, "# Assertion \"!(%s [= %d])\" Failed\n" \
- "file %s; line %d\n", \
- QuoteExceptionString(assertion), __privateAssertion, __FILE__, __LINE__); \
- { action } \
- } \
- } while (false)
- #else
- #define ncheck_action(assertion, action)
- #endif
- #if __DEBUGSMALL
- #define require(assertion, exception) \
- do { \
- if (assertion) ; \
- else { \
- __DebuggerBreak; \
- goto exception; \
- resumeLabel(exception); \
- } \
- } while (false)
- #elif DEBUGLEVEL == DEBUGON
- #define require(assertion, exception) \
- do { \
- if (assertion) ; \
- else { \
- dprintf(notrace, "# Assertion \"%s\" Failed\n" \
- "# Exception \"%s\" Raised\n", \
- QuoteExceptionString(assertion), \
- QuoteExceptionString(exception)); \
- goto exception; \
- resumeLabel(exception); \
- } \
- } while (false)
- #elif DEBUGLEVEL == DEBUGFULL
- #define require(assertion, exception) \
- do { \
- if (assertion) ; \
- else { \
- dprintf(notrace, "# Assertion \"%s\" Failed\n" \
- "# Exception \"%s\" Raised\n" \
- "file %s; line %d\n", \
- QuoteExceptionString(assertion), \
- QuoteExceptionString(exception), \
- __FILE__, __LINE__); \
- goto exception; \
- resumeLabel(exception); \
- } \
- } while (false)
- #else
- #define require(assertion, exception) \
- do { \
- if (assertion) ; \
- else { \
- goto exception; \
- resumeLabel(exception); \
- } \
- } while (false)
- #endif
- #if __DEBUGSMALL
- #define nrequire(assertion, exception) \
- do { \
- if (assertion) { \
- DebugStr(); \
- goto exception; \
- resumeLabel(exception); \
- } \
- } while (false)
- #elif DEBUGLEVEL == DEBUGON
- #define nrequire(assertion, exception) \
- do { \
- void* __privateAssertion = (void*)(assertion); \
- \
- if (__privateAssertion) { \
- dprintf(notrace, "# Assertion \"!(%s [= %d])\" Failed\n" \
- "# Exception \"%s\" Raised\n", \
- QuoteExceptionString(assertion), __privateAssertion, \
- QuoteExceptionString(exception)); \
- goto exception; \
- resumeLabel(exception); \
- } \
- } while (false)
- #elif DEBUGLEVEL == DEBUGFULL
- #define nrequire(assertion, exception) \
- do { \
- void* __privateAssertion = (void*)(assertion); \
- \
- if (__privateAssertion) { \
- dprintf(notrace, "# Assertion \"!(%s [= %d])\" Failed\n" \
- "# Exception \"%s\" Raised\n" \
- "file %s; line %d\n", \
- QuoteExceptionString(assertion), \
- __privateAssertion, \
- QuoteExceptionString(exception), __FILE__, \
- __LINE__); \
- goto exception; \
- resumeLabel(exception); \
- } \
- } while (false)
- #else
- #define nrequire(assertion, exception) \
- do { \
- if (assertion) { \
- goto exception; \
- resumeLabel(exception); \
- } \
- } while (false)
- #endif
- #if __DEBUGSMALL
- #define require_action(assertion, exception, action) \
- do { \
- if (assertion) ; \
- else { \
- __DebuggerBreak; \
- { action } \
- goto exception; \
- resumeLabel(exception); \
- } \
- } while (false)
- #elif DEBUGLEVEL == DEBUGON
- #define require_action(assertion, exception, action) \
- do { \
- if (assertion) ; \
- else { \
- dprintf(notrace, "# Assertion \"%s\" Failed\n" \
- "# Exception \"%s\" Raised\n", \
- QuoteExceptionString(assertion), QuoteExceptionString(exception)); \
- { action } \
- goto exception; \
- resumeLabel(exception); \
- } \
- } while (false)
- #elif DEBUGLEVEL == DEBUGFULL
- #define require_action(assertion, exception, action) \
- do { \
- if (assertion) ; \
- else { \
- dprintf(notrace, "# Assertion \"%s\" Failed\n" \
- "# Exception \"%s\" Raised\n" \
- "file %s; line %d\n", \
- QuoteExceptionString(assertion), \
- QuoteExceptionString(exception), __FILE__, __LINE__); \
- { action } \
- goto exception; \
- resumeLabel(exception); \
- } \
- } while (false)
- #else
- #define require_action(assertion, exception, action) \
- do { \
- if (assertion) ; \
- else { \
- { action } \
- goto exception; \
- resumeLabel(exception); \
- } \
- } while (false)
- #endif
- #if __DEBUGSMALL
- #define nrequire_action(assertion, exception, action) \
- do { \
- if (assertion) { \
- __DebuggerBreak; \
- { action } \
- goto exception; \
- resumeLabel(exception); \
- } \
- } while (false)
- #elif DEBUGLEVEL == DEBUGON
- #define nrequire_action(assertion, exception, action) \
- do { \
- void* __privateAssertion = (void*)(assertion); \
- \
- if (__privateAssertion) { \
- dprintf(notrace, "# Assertion \"!(%s [= %d])\" Failed\n" \
- "# Exception \"%s\" Raised\n", \
- QuoteExceptionString(assertion), __privateAssertion, \
- QuoteExceptionString(exception)); \
- { action } \
- goto exception; \
- resumeLabel(exception); \
- } \
- } while (false)
- #elif DEBUGLEVEL == DEBUGFULL
- #define nrequire_action(assertion, exception, action) \
- do { \
- void* __privateAssertion = (void*)(assertion); \
- \
- if (__privateAssertion) { \
- dprintf(notrace, "# Assertion \"!(%s [= %d])\" Failed\n" \
- "# Exception \"%s\" Raised\n" \
- "file %s; line %d\n", \
- QuoteExceptionString(assertion), __privateAssertion, \
- QuoteExceptionString(exception), __FILE__, \
- __LINE__); \
- { action } \
- goto exception; \
- resumeLabel(exception); \
- } \
- } while (false)
- #else
- #define nrequire_action(assertion, exception, action) \
- do { \
- if (assertion) { \
- { action } \
- goto exception; \
- resumeLabel(exception); \
- } \
- } while (false)
- #endif
- #define resume(exception) \
- do { \
- goto resume_##exception; \
- } while (false)
-
- #if PRAGMA_IMPORT_SUPPORTED
- #pragma import off
- #endif
-
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=reset
- #endif
-
- #ifdef __cplusplus
- }
- #endif
-
- #endif /* __EXCEPTIONS__ */
-